<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>增加采购人</title>
		<link rel="stylesheet" href="layui/css/layui.css" media="all">
	</head>
	<body>
		<form class="layui-form" style="margin-top: 30px;">
			<div class="layui-form-item" style="width: 600px;">
			    <label class="layui-form-label">采购人编号</label>
			    <div class="layui-input-block">
			      <input type="text" name="buyerId" lay-verify="required|number" autocomplete="off" class="layui-input">
			    </div>
			</div>
		    <div class="layui-form-item" style="width: 600px;">
		        <label class="layui-form-label">采购人姓名</label>
		        <div class="layui-input-block">
		          <input type="text" name="buyerName" lay-verify="required" autocomplete="off" class="layui-input">
		        </div>
		    </div>
			<div class="layui-form-item" style="width: 600px;">
			    <label class="layui-form-label">采购人电话</label>
			    <div class="layui-input-block">
			      <input type="text" name="buyerPhone" lay-verify="required|phone" autocomplete="off" class="layui-input">
			    </div>
			</div>
			<div class="layui-form-item" style="width: 600px;">
			    <div class="layui-input-block" style="text-align:center;">
			      <button class="layui-btn" lay-submit=""  lay-filter="demo1">立即提交</button>&nbsp;&nbsp;&nbsp;&nbsp;
			      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
			    </div>
			</div>
		</form>
		
		<script src="js/jquery-3.4.1.js"></script>
		<script src="layui/layui.js"></script>
		<script>
			layui.use(['form'], function(){
			    var form = layui.form
			    ,layer = layui.layer;
				  
				//监听提交
				form.on('submit(demo1)', function(data){
				    // layer.alert(JSON.stringify(data.field), {
				    //   title: '最终的提交信息'
				    // })
					
					$.ajax({
						type:"post",
						url:"http://localhost:8081/user/registBuyer",
						async:true,
						contentType:"application/json;charset=UTF-8",
						data:JSON.stringify(data.field),
						xhrFields: {
							withCredentials: true
						},
						success:function(res){
							$('input').val("");
							//sessionStorage.setItem("userName",res.data);
							// console.log(res);
							if(res.code>=0){
								layer.msg(res.msg,{time: 1000},function () {
									var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
									parent.layer.close(index); //再执行关闭
									parent.tableIn.reload();
								});
							}else{
								layer.msg(res.msg);
							}
						}
					});
				    return false;
				});
			});
		</script>
	</body>
</html>
